// RichAssetsLogic.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include <jni.h>
#include "com_richasset_server_CRoom.h"

#include "RoomManager.h"
#include "Sender.h"
#include <stdlib.h>
JNIEXPORT void JNICALL Java_com_richasset_server_CRoom_setSenderNative
  (JNIEnv* env, jobject room, jint nRoomId)
{
	CRoomManager::getInstance()->createRoom(nRoomId);
	CRoomManager::getInstance()->initializeRoom(nRoomId);
	CSender::getInstance()->renew(env, room, nRoomId);
}
/*
 * Class:     com_richasset_server_LogicJni
 * Method:    useChip
 * Signature: (II)V
 */

JNIEXPORT void JNICALL Java_com_richasset_server_CRoom_useChipNative
  (JNIEnv* env, jobject room, jint nRoomId, jint userSlot, jint chipId)
{
	//use chip ( A turn of GameLogic )
	cout<<"-----------------------LogicTurn_Begin["<<nRoomId<<"]----------------------------"<<endl;
	CSender::getInstance()->renew(env, room, nRoomId);
	CRoomManager::getInstance()->RoomGame(nRoomId, (PLAYER)(userSlot), chipId);
	CSender::getInstance()->sendTurnover((int)(userSlot), nRoomId);
	cout<<"-----------------------LogicTurn_End["<<nRoomId<<"]------------------------------"<<endl;
}

/*
 * Class:     com_richasset_server_LogicJni
 * Method:    clear
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_com_richasset_server_CRoom_clearNative
  (JNIEnv* env, jobject room, jint nRoomId)
{
	CRoomManager::getInstance()->initializeRoom(nRoomId);
}

/*
 * Class:     com_richasset_server_LogicJni
 * Method:    enterUser
 * Signature: (II)V
 */
JNIEXPORT void JNICALL Java_com_richasset_server_CRoom_enterUserNative
  (JNIEnv* env, jobject room, jint nRoomId, jint userSlot, jint userID)
{
	CSender::getInstance()->setUserID(nRoomId, userSlot, userID);
	CRoomManager::getInstance()->enterUser(nRoomId);
}
